#ifndef SYSTEM_HPP
#define SYSTEM_HPP

#include "sdk_config.h"
#include "core/timespan.hpp"

class ISystem;

PI_API void register_system(ISystem *system);
PI_API void unregister_system(ISystem *system);

class PI_API ISystem {
public:
    virtual ~ISystem() = default;

    virtual u8 tick_priority() const = 0;

    virtual void pre_tick();

    virtual void on_tick(pi_time_t delta, pi_time_t time) = 0;

    virtual void after_tick();
};

template <u8 Priority>
class PrioritySystem: public ISystem {
public:
    PI_INLINE PrioritySystem() { register_system(this); }
    PI_INLINE ~PrioritySystem() { unregister_system(this); }

    u8 tick_priority() const override final { return Priority; }
};

#endif /* SYSTEM_HPP */
